 
 #include"../../common/detail.hpp"
 #include"../../server/rpc_server.hpp"

// void RpconMessage(const rpc::BaseConnection::ptr &conn, const rpc::RequestMessage::ptr &msg)
// {

//     std::cout << "收到RPC请求消息" << (int)msg->getMytype() << std::endl;
//     std::string str = msg->serilize();
//     std::cout << str << std::endl;
//     // 构建一个响应
//     auto rsp = rpc::MessageFactory::create<rpc::RpcResponse>();
//     rsp->setId("111");
//     rsp->setMytype(rpc::MY_TYPE::RSP_RPC);
//     rsp->setRecode(rpc::MY_CODE::RCODE_OK);
//     rsp->setResult(33);
//     rsp->setMethod("add");
//     conn->send(rsp);
// }

// void TopiconMessage(const rpc::BaseConnection::ptr &conn, const rpc::TopicRequest::ptr &msg)
// {
//     std::cout << "收到topic请求" << msg->getKeyTopic() << std::endl;
//     std::string str = msg->serilize();
//     std::cout << str << std::endl;
//     // 构建一个响应
//     auto rsp = rpc::MessageFactory::create<rpc::TopicResponse>();
//     rsp->setId("222");
//     rsp->setMytype(rpc::MY_TYPE::RSP_TOPIC);
//     rsp->setRecode(rpc::MY_CODE::RCODE_OK);
//     conn->send(rsp);
// }

void Add(const Json::Value& req,Json::Value&rsp)
{
    int num1 = req["num1"].asInt();
    int num2 = req["num2"].asInt();
    rsp = num1 + num2;
}

int main()
{
    //构建desc对象
    auto desc_factory = std::shared_ptr<rpc::server::DescribeFactory>(new rpc::server::DescribeFactory());
    desc_factory->setMethod("Add");
    desc_factory->PushParam("num1", rpc::server::v_type::INT);
    desc_factory->PushParam("num2", rpc::server::v_type::INT);
    desc_factory->setRtype(rpc::server::INT);
    desc_factory->setCallback(Add);
    rpc::server::RpcServer server(rpc::Address("127.0.0.1",9090));
    server.RegistryMethod(desc_factory->build());
    server.start();
    return 0;
}
